home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Dev / misc / temgen.lha / Temgen / tg-0.11 / errtab.c < prev    next >
C/C++ Source or Header  |  2002-12-18  |  1KB  |  44 lines

  1. #include "alloc.h"
  2. #include "sysdefs.h"
  3. #include "atom.h"
  4. #include "lintab.h"
  5.  
  6. static struct lintab *errtab = NULL;
  7.  
  8. struct error {
  9.         int file, line, msgn;
  10. };
  11.  
  12. void save_error( const char *fname, int line, const char *msg )
  13. {
  14.         struct error *e;
  15.         int maxndx; 
  16.         
  17.         if ( !errtab ) errtab = new_lintab( 128, 128 );
  18.         if ( !errtab ) return;
  19.  
  20.         maxndx = lt_maxindex( errtab );
  21.         if ( maxndx < 0 ) maxndx = -1;
  22.         e = (struct error*)MALLOC( sizeof(*e) );
  23.         if ( e ) {
  24.                 e->file = atom( fname );
  25.                 e->line = line;
  26.                 e->msgn = atom( msg );  
  27.                 lt_set( errtab, maxndx+1, e );
  28.         }
  29. }
  30.  
  31. const char *next_errmsg( void )
  32. {
  33.         static char buf[ 256 ];
  34.         static int next = 0;
  35.         struct error *e;
  36.         if ( !errtab ) return NULL;
  37.         if ( next > lt_maxindex( errtab )) return NULL;
  38.         e = (struct error*)lt_get( errtab, next++ );
  39.         if ( !e ) return NULL;
  40.         snprintf( buf, sizeof(buf), "%s:%d %s", atom_name(e->file), 
  41.                 e->line, atom_name(e->msgn) );
  42.         return buf;
  43. }
  44.